<%@ page contentType="text/html;charset=UTF-8"
	import="petertel.pbx.conf.*"%>
<%@ include file="common/common.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>日志配置</title>
<link href="${contextPath}/style/common.css" rel="stylesheet"
	type="text/css" />
<script type="text/javascript">

	function redApply(){
		document.getElementById("applyButton").style.backgroundColor="red";
	}

	function reset() {
		location.href = "${contextPath}/loggerConf/reset.fb";
	}
	function insert(index) {
		if (index == undefined) {
			index = 0;
		}
		index--;
		var filename = document.getElementById("newLogfile").value;
		location.href = "${contextPath}/loggerConf/insert.fb?index="+index+"&filename="+filename;
	}
	function remove(index) {
		if (index == undefined) {
			index = 0;
		}
		index--;
		location.href = "${contextPath}/loggerConf/remove.fb?index="+index;
	}
	function apply() {
		location.href = "${contextPath}/loggerConf/apply.fb";
	}
	function checkLoglevel(index, loglevel, checked) {
		index--;
		var url = "${contextPath}/loggerConf/checkLoglevel.fb?index="+index+"&loglevel="+loglevel+"&checked="+checked;
		load(url, function(){});
		document.getElementById("applyButton").className="button-red";
	}
function load(url, callback) {  
        var xhr;  
          
        if(typeof XMLHttpRequest !== 'undefined') xhr = new XMLHttpRequest();  
        else {  
            var versions = ["MSXML2.XmlHttp.5.0",   
                            "MSXML2.XmlHttp.4.0",  
                            "MSXML2.XmlHttp.3.0",   
                            "MSXML2.XmlHttp.2.0",  
                            "Microsoft.XmlHttp"]  
  
             for(var i = 0, len = versions.length; i < len; i++) {  
                try {  
                    xhr = new ActiveXObject(versions[i]);  
                    break;  
                }  
                catch(e){}  
             } // end for  
        }  
          
        xhr.onreadystatechange = ensureReadiness;  
          
        function ensureReadiness() {  
            if(xhr.readyState < 4) {  
                return;  
            }  
              
            if(xhr.status !== 200) {  
                return;  
            }  
  
            // all is well    
            if(xhr.readyState === 4) {  
                callback(xhr);  
            }             
        }  
          
        xhr.open('GET', url, true);  
        xhr.send('');  
    }  
</script>
</head>
<body>
	<div id="tools" class="listbar">
		<div style="float: left;">
			<div style="float: left;" class="input-text">名称：</div>
			<input name="name" type="text" class="gray" />
		</div>
		<div style="float: left; margin-left: 5px;">
			<input type="submit" value="重置" class="button-blue"
				onclick="reset();">
		</div>
		<div style="float: left; margin-left: 5px;">
			<input type="submit" id="applyButton" value="应用" class="${loggerConf.applyButtonClass} "
				onclick="apply();">
		</div>
	</div>
	<div class="listTable">
		<table class="table-gray">
			<tr class="thead-gray">
				<td style="height: 28px;">文件名</td>
				<td>日志级别</td>
				<td>操作</td>
			</tr>
			<c:forEach items="${loggerConf.logfiles}" var="logfile"
				varStatus="vs">
					<tr class="${loggerConf.toggle?'tr-white':'tr-gray'}">
						<td style="height: 25px;">${logfile.filename}</td>
						<td><c:forEach items="${logfile.loglevels}" var="loglevel">
								<input type="checkbox" ${loglevel.checked?'checked':''}
									 onclick="checkLoglevel(${vs.count}, '${loglevel.type}', this.checked)" />${loglevel.type}
									</c:forEach></td>
						<td><input type="button" value="删除"
							onclick="remove(${vs.count})" /></td>
					</tr>
			</c:forEach>
			<tr class="${loggerConf.toggle?'tr-white':'tr-gray'}">
				<td><input id="newLogfile"/></td>
				<td></td>
				<td><input type="button" value="添加" onclick="insert()" /></td>
			</tr>
		</table>
	</div>
</body>
</html>